﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DesignPattern.StatePattern
{
    class Context
    {
        private State state;

        public State State
        {
            get { return state; }
            set { state = value; }
        }

        public Context()
        {
            state = new StateA();
        }

        public Context(State state)
        {
            this.state = state;
        }

        public void Quest()
        {
            state.Handle(this);
        }
    }

    interface State
    {
        void Handle(Context context);
    }

    class StateA:State
    {
        public void Handle(Context context)
        {
            context.State = new StateB();
            Console.WriteLine("切换到状态B");
        }
    }

    class StateB:State
    {
        public void Handle(Context context)
        {
            context.State = new StateC();
            Console.WriteLine("切换到状态C");
        }
    }

    class StateC : State
    {
        public void Handle(Context context)
        {
            context.State = new StateA();
            Console.WriteLine("切换到状态A");
        }
    }
}
